﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using YAPL.Language.Core.Types;

namespace YAPL.Language.Core.Lib.GlobalFunctions {
	public class ClassConstructor : YAPLFunction {
		public ClassConstructor(string ownerName) : base(FunctionNames.ClassConstructor, GCL.Get(ownerName)) {}
		public override YAPLObject Call(Scope scope) {
			ParseScope(scope);
			var obj = _owner.Instantiate();
			var initializer = obj.YAPLType.Methods[FunctionNames.ClassInitializer];
			if (initializer.Name != FunctionNames.NoMethod) {
				//call initializer method
				scope[SELF_PARAMETER] = obj;
				initializer.Call(scope);
			}
			return obj;
		}

		public override bool CanPrecompute {
			get {
				return false;
			}
		}
	}

}
